package com.example.my_music_palyer.common.tools;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * 登录调试工具
 * 用于测试和验证登录逻辑
 */
public class LoginDebug {
    
    public static void main(String[] args) {
        System.out.println("=== 登录调试工具 ===");
        
        // 创建BCrypt编码器
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        
        // 测试密码
        String testPassword = "123456";
        
        // 测试不同的哈希值
        String[] testHashes = {
            "$2a$10$N.zmdr9k7uOCQb376NoUnuTJ8iAt6Z5EHsM8lE9lBOsl7iKTVEFDa",  // 原来的错误哈希
            "$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2uheWG/igi.",  // 正确的哈希
            "$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG",  // 另一个可能的哈希
            "$2a$10$3NxM9VqH8K2L1P7Q4R5S6T9U0V1W2X3Y4Z5A6B7C8D9E0F1G2H3I4J"   // 随机哈希
        };
        
        System.out.println("测试密码: " + testPassword);
        System.out.println();
        
        for (int i = 0; i < testHashes.length; i++) {
            String hash = testHashes[i];
            boolean isValid = encoder.matches(testPassword, hash);
            System.out.println("哈希 " + (i+1) + ": " + hash);
            System.out.println("验证结果: " + isValid);
            System.out.println();
        }
        
        // 生成新的哈希值
        System.out.println("=== 生成新哈希值 ===");
        String newHash = encoder.encode(testPassword);
        System.out.println("新生成的哈希: " + newHash);
        
        boolean newIsValid = encoder.matches(testPassword, newHash);
        System.out.println("新哈希验证: " + newIsValid);
        
        // 测试直接使用BCryptPasswordEncoder
        System.out.println();
        System.out.println("=== 测试直接使用BCryptPasswordEncoder ===");
        String directHash = encoder.encode(testPassword);
        System.out.println("直接生成的哈希: " + directHash);
        
        boolean directIsValid = encoder.matches(testPassword, directHash);
        System.out.println("直接哈希验证: " + directIsValid);
    }
}
